package work.shyk.gaas;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * description: <br>
 * createTime: 2020/11/617:35 <br>
 *
 * @author zzh
 */
public class Test {
    public static final long MILLISECONDS_A_DAY = 24 * 60 * 60 * 1000;
    public static  List<String> getDateList(Date minDate) {
        List<String> result = new ArrayList<String>();
        Date maxDate = new Date();
        if(minDate == null) {
            minDate = new Date(maxDate.getTime() - 30 * MILLISECONDS_A_DAY);
        }
        long t1 = 0l;
        long t2 = 0l;
        try {
            if (null != minDate) {
                t1 = maxDate.getTime();
                t2 = minDate.getTime();
                int cycleMin = (int) ((t1 - t2) / (MILLISECONDS_A_DAY) - 1);
                if (cycleMin > 0) {
                    for (int i = 0; i < cycleMin; i++) {
                        String dayChanges = DateUtils.getDayChanges(maxDate, i - cycleMin);
                        result.add(dayChanges);
                    }
                }
            } else {
                String dayChanges = DateUtils.getDayChanges(maxDate, -1);
                result.add(dayChanges);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    public static void main(String[] args) throws ParseException {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(getDateList(format.parse("2020-11-3")));
    }
}
